/*
 * Zirco Browser for Android
 * 
 * Copyright (C) 2010 J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.gogowan.agroenterprise.model;

import com.gogowan.agroenterprise.contorl.IJSON;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * @author Administrator
 *
 */
public class JumpTable extends Version implements IJSON{
	/**
	 * 是否跳转 0:所有网址皆不跳转 1:只跳转在列表内的网址 2:所有网址皆跳转
	 * 
	 */
	private int isjump;
	private String[] jumptable;
	private String filterweb;
	public int getIsjump() {
		return isjump;
	}
	public void setIsjump(int isjump) {
		this.isjump = isjump;
	}
	public String[] getJumptable() {
		return jumptable;
	}
	public void setJumptable(String[] jumptable) {
		this.jumptable = jumptable;
	}
	public String getFilterweb() {
		return filterweb;
	}
	public void setFilterweb(String filterweb) {
		this.filterweb = filterweb;
	}

	@Override
	public Object fromJSON(String jsonString) {
		// TODO Auto-generated method stub
		Version version=null;
		if(jsonString==null||jsonString.equals(""))
		{
			return version;
		}
		try {
			version=new Version();
			JSONObject json = new JSONObject(jsonString);
			String ver = json.optString("version");
			String describe = json.optString("describe");
			int isforceupdate = json.getInt("isforceupdate");
			String date = json.optString("date");
			String url = json.optString("url");

			version.setVersion(ver);
			version.setDescribe(describe);
			version.setIsforceupdate(isforceupdate);
			version.setDate(date);
			version.setUrl(url);

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return version;
	}

	@Override
	public String toJSON(Object objectVal) {
		// TODO Auto-generated method stub
		JSONObject json = null;
		try {
			json = new JSONObject();
			Version version=(Version)objectVal;
			json.put("version", version.getVersion());
			json.put("describe", version.getDescribe());
			json.put("isforceupdate",version.getIsforceupdate());
			json.put("date", version.getDate());
			json.put("url", version.getUrl());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
		return json.toString();
	}
}
